<template>
	<view>
		<view class="user-vip">
			<view class="header">
				<view class="user-vip-info row">
					<custom-image width="110rpx" height="110rpx" round :src="userInfo.avatar"></custom-image>
					<view class="ml20 column">
						<view class="user-text white xxl row">{{userInfo.nickname}}</view>
						<view class="user-level white xs row-center">当前等级：{{userInfo.level_name || "无"}}</view>
					</view>
				</view>
			</view>
			<view class="content">
				<view class="vip-swiper-container">
					<swiper class="swiper" style="height: 320rpx" previous-margin="60rpx" next-margin="60rpx"
						display-multiple-items="1" :current="currentIndex" @change="bindchange">
						<swiper-item class="swiper-item" v-for="(item, index) in levelList" :key="index">
							<view class="vip-card-item"
								:style="'background-image: url(' + item.background_image + ');'">
								<view class="top-bar row-between">
									<view class="status">
										<view v-if="item.current_level_status == 1">当前等级</view>
										<view v-else-if="item.current_level_status == -1">未解锁</view>
										<view v-else-if="item.current_level_status == 0">已解锁</view>
									</view>
									<image class="grade-icon" :src="item.image" mode="heightFix"></image>
								</view>
								<view class="row-between vip-name white">
									<view class="">{{item.name}}</view>
									<!-- <view class="sm">{{item.next_level}}</view> -->
								</view>
								<!-- 								<view class="row-center" v-if="item.diff_growth_percent">
									<view class="vip-progress bg-white row">
										<view class="vip-progress-bar" :style="'width: ' + (item.diff_growth_percent*100) + '%'"></view>
									</view>
								</view> -->

								<view class="num-box">
									<text class="big">80</text>
									<text>/180</text>
									<u-icon name="arrow-right" size="24"></u-icon>
								</view>

								<view class="footer-box">
									<view class="left">
										<view class="row-center">
											<view class="vip-progress bg-white row">
												<view class="vip-progress-bar" :style="'width: ' + (0.7*100) + '%'">
												</view>
											</view>
										</view>
										<view class="desc">还需<text class="val">充值100元</text>可升级</view>
										<!-- 				<view class="row-between mt20" style="padding: 0 30rpx">
											<navigator hover-class="none" class="row">
												<view class="sm white" style="line-height: 36rpx">
													{{item.current_level_status == 0 ? '当前高于该等级' : item.current_growth_tips}}
												</view>
											</navigator>
											<view class="white">{{item.diff_growth_tips}}</view>
										</view> -->
									</view>
									<view class="right">
										<view class="btn" @tap="onClickUpgrate">一键升级</view>
									</view>
								</view>

							</view>
						</swiper-item>
					</swiper>
				</view>
				<view class="vip-grade-rule">
					<view class="title row">
						<view class="line br60"></view>
						<view class="xl ml20 bold">会员规则</view>
						<!-- 						<view class="xl ml20 bold">成长值规则</view> -->
					</view>
					<text class="rule-content column lighter ml20">
						{{growthRule}}
					</text>
				</view>
				<view class="vip-rights">
					<view class="title row">
						<view class="line br60"></view>
						<view class="xl ml20 bold">会员权益</view>
					</view>
					<view class="rights-list row">
						<view v-for="(item, index) in privilegeList" :key="index" class="rights-item column-center">
							<image class="mb10" :src="item.image"></image>
							<view class="sm">{{item.name}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<loading-view v-if="!userInfo.nickname"></loading-view>


		<u-popup v-model="showPop" mode="bottom" border-radius="14" :closeable="true" @close="onClose"
			:safe-area-inset-bottom="true">
			<view class="bg-white select-vip-level-contain">
				<view class="main-container">
					<view class="title">升级会员</view>
					<scroll-view scroll-x class="item-list">
						<view class="item-wrap">
							<view class="item" :class="selected === item.id ? 'active' : ''" v-for="(item, index) in dataList" :key="index">
								<view class="item-main">
									<view class="item-title">升至 {{item.name}}</view>
									<price-format :color="selected === item.id ? '#504632' : '#999'" :first-size="64" :subscript-size="40" :price="item.price"
										:weight="600"></price-format>
									<view class="line-through muted md">
										<price-format :color="selected === item.id ? '#BDA779' : '#ccc'" :price="item.old_price"></price-format>
									</view>
								</view>
								<view class="item-footer">
									<view class="text">有效期至</view>
									<view class="date">{{item.date}}</view>
								</view>
							</view>
						</view>
						
					</scroll-view>
				</view>
				<view class="footer-container">
					<view class="btn" :class="selected ? '' : 'disabled'" @tap="onClickConfirmBtn">￥98 立即升级</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		getLevelList
	} from '@/api/user';

	export default {
		data() {
			return {
				userInfo: {},
				currentIndex: 0,
				levelList: [],
				growthRule: "",
				privilegeList: [],


				showPop: false,
				selected: '1',
				dataList: [{
						name: "青铜会员",
						old_price: '128',
						date: '2024.01.24',
						price: '50',
						id: '1'
					},
					{
						name: "白银会员",
						old_price: '128',
						date: '2024.01.24',
						price: '50',
						id: '2'
					},
					{
						name: "黄金会员",
						old_price: '128',
						date: '2024.01.24',
						price: '50',
						id: '3'
					}, {
						name: "黄金会员",
						old_price: '128',
						date: '2024.01.24',
						price: '50',
						id: '4'
					}, {
						name: "黄金会员",
						old_price: '128',
						date: '2024.01.24',
						price: '50',
						id: '5'
					},
				]
			};
		},

		components: {},
		props: {},

		onLoad: function(options) {
			this.getLevelListFun();
		},


		methods: {
			onClickUpgrate(){
				this.showPop = true
			},
			bindchange(e) {
				let {
					current
				} = e.detail;
				let currentLevel = this.levelList[current];
				this.currentIndex = current
				this.privilegeList = currentLevel.level_privilege
			},

			getLevelListFun() {
				getLevelList().then(res => {
					const {
						code,
						data
					} = res;
					if (code != 1) return;
					const {
						user,
						growth_rule,
						level_list
					} = data;
					let index = level_list.findIndex(item => item.current_level_status == 1);
					if (index == -1) index = 0;
					this.userInfo = user
					this.growthRule = growth_rule
					this.levelList = level_list
					console.log("level_list", level_list)
					this.currentIndex = index
					this.privilegeList = level_list[index].level_privilege
				});
			},
		}
	};
</script>
<style lang="scss" scoped>
	@import "index.scss";
</style>